<template>
  <!-- 系统管理 -->
  <div class="app-container">
    <div class="mainbox">
      <!-- 顶部操作 -->
      <div class="filter-container">
        <el-form ref="filterFormRef" :inline="true" :model="filterForm">
          <el-form-item label="考察时间:" prop="times">
            <el-date-picker
              v-model="filterForm.times"
              type="daterange"
              :picker-options="pickerOptions"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-form>
        <div class="flex-1" />
        <el-button type="primary" @click="$_handleFilter">查询</el-button>
        <el-button @click="$_handleReset">重置</el-button>

      </div>
      <!-- 表格 -->
      <div class="table-container table-fullscreen">
        <div class="table-opt-container">
          <el-button
            v-permission="['FOLLOWUP_ADD_BUTTON']"
            type="primary"
            icon="el-icon-plus"
            @click="handleAdd"
          >
            新增
          </el-button>
          <el-button
            v-permission="['FOLLOWUP_DOWNLOAD_BUTTON']"
            icon="el-icon-download"
            @click="handleExport('d')"
          >
            下载模板
          </el-button>
          <el-button
            v-permission="['FOLLOWUP_IMPORT_BUTTON']"
            icon="el-icon-folder-add"
            type="primary"
            @click="$_handleImport()"
          >
            导入
          </el-button>
          <div class="flex-1" />
          <dt-dialog-column :columns="columns" @queryTable="getList" />
        </div>
        <el-table
          ref="table"
          v-loading="MX_listLoading"
          :data="MX_list"
          border
          highlight-current-row
          :row-key="$_getRowKey"
          style="width: 100%;text-align:center"
          :header-cell-style="MX_headerCellStyle"
        >
          <template slot="empty">
            <p>{{ $store.getters.dataText }}</p>
          </template>
          <el-table-column
            fixed="left"
            type="index"
            label="序号"
            width="70"
            align="center"
            :index="$_tableIndex"
          />
          <el-table-column
            v-for="item in columns"
            :key="item.prop"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :min-width="item.minWidth"
            :formatter="item.formatter"
            align="center"
          />
          <el-table-column
            :key="Math.random()"
            fixed="right"
            label="操作"
            width="220px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                v-permission="['FOLLOWUP_DETAIL_BUTTON']"
                size="mini"
                class="tBtn"
                @click="$_handleDetail(scope.row)"
              >详情</el-button>
              <el-button
                v-permission="['FOLLOWUP_UPDATE_BUTTON']"
                size="mini"
                class="tBtn"
                @click="handleEdit(scope.row)"
              >修改</el-button>
              <el-button
                v-permission="['FOLLOWUP_DEL_BUTTON']"
                size="mini"
                type="danger"
                class="tBtn"
                @click="handleDelete(scope.row.visitsId)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <dt-pagination
          v-show="MX_total > 0"
          :total="MX_total"
          :page.sync="MX_pageNav.pageNo"
          :limit.sync="MX_pageNav.pageSize"
          @pagination="getList"
        />
      </div>
      <DialogForm ref="dialogForm" labelWidth="140px" :formDesignList="formDesignList" />
      <dtDialog
        title="导入"
        class="get-page-form-import-dialog"
        :visible.sync="MX_fileUploadVisible"
        width="620px"
        :is-loading="MX_uploadLoading"
        @closeDialog="MX_fileUploadVisible = false"
        @comfirmBtn="$_importDataSave(importApi, {venerableId})"
      >
        <el-form slot="content">
          <div class="">
            <dt-importFile ref="dtImportFileRef" :down-load-template="handleImportTemplate" :type="fileName" />
          </div>
        </el-form>
      </dtDialog>
    </div>
  </div>
</template>
<script>
import intservApi from '@/api/investment/intserv'
import DialogForm from '@/views/investment/components/DialogForm'
import commonList from "@/utils/mixins/investment/commonList";

export default {
  name: 'FollowUpList',
  components: {
    DialogForm
  },
  mixins: [commonList],
  data() {
    return {
      venerableId: null,
      filterForm: {
        times: ''
      },
      fileName: '回访记录数据导入',
      handleImportTemplate: intservApi.downloadFollowUp,
      importApi: intservApi.importFollowUp,
      // 列信息
      columns: [
        { prop: 'visitsDate', label: `考察时间`, minWidth: '100px' },
        { prop: 'visitsPlace', label: `地点` },
        { prop: 'visitsAmount', label: `金额` },
        { prop: 'visitsObjective', label: `目的`, width: '140px'  },
        { prop: 'reception', label: `接待人`, width: '80px'  },
        { prop: 'visitsContent', label: `内容`, minWidth: '100px' },
        { prop: 'createTime', label: `创建时间`, minWidth: '100px' }
      ],
      formDesignList: [
        { type: 'date', prop: 'visitsDate', label: `考察时间`, format: 'yyyy-MM-dd', rules: [{ required: true, message: '请输入考察时间', trigger: 'blur' }] },
        { type: 'text', prop: 'visitsPlace', label: `地点`, rules: [{ required: true, message: '请输入地点', trigger: 'blur' }] },
        { type: 'text', prop: 'visitsAmount', label: `金额`, rules: [{ required: true, message: '请输入金额', trigger: 'blur' }] },
        { type: 'text', prop: 'visitsObjective', label: `目的`, rules: [{ required: true, message: '请输入目的', trigger: 'blur' }] },
        { type: 'text', prop: 'reception', label: `接待人`, rules: [{ required: true, message: '请输入接待人', trigger: 'blur' }] },
        { type: 'textarea', prop: 'visitsContent', label: `内容`, maxlength: 1000, autosize: {minRows: 3, maxRows: 6}, rules: [{ required: true, message: '请输入内容', trigger: 'blur' }] },
        { type: 'text', prop: 'createTime', label: `创建时间`, showTypes: ['detail'] },
      ],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
    }
  },
  watch:{
    'filterForm.times'(val){
      this.$set(this.filterForm, 'searchBeginTime', !!val ? val[0] : '')
      this.$set(this.filterForm, 'searchEndTime', !!val ? val[1] : '')
    },
    venerableId(val, old){
      if (val !== old){
        this.getList()
      }
    }
  },
  created() {
    if (!this.$route.query.id){
      this.$message.error('请带入乡贤数据标识！')
      return
    }
    this.venerableId = this.$route.query.id
  },
  activated() {
    this.venerableId = this.$route.query.id
  },
  methods: {
    // 获取页面列表
    getList() {
      let filterForm = JSON.parse(JSON.stringify(this.filterForm))
      delete filterForm.times
      this.$_getList(intservApi.getFollowUpList,{
        venerableId: this.venerableId,
        ...filterForm,
        ...this.MX_pageNav
      })
    },
    // 编辑按钮
    handleEdit(data) {
      this.$refs.dialogForm.open('update', intservApi.updateFollowUpItem, data || this.MX_applicationMsg)
    },
    // 添加按钮
    handleAdd() {
      this.$refs.dialogForm.open('add', intservApi.addFollowUpItem, { venerableId: this.venerableId })
    },
    // 删除按钮
    handleDelete(id) {
      this.$_handleDelete(intservApi.delFollowUpItem, [id], 'visitsIds')
    },
    /** 下载按钮操作 */
    handleExport() {
      this.$_handleDownload(this.handleImportTemplate, `${this.fileName}模板`);
    },
  }
}
</script>

<style lang="scss" scoped>
.tBtn{
  margin-top: 3px;
  margin-bottom: 3px;
}
</style>
